package com.cskaoyan.service;

import com.cskaoyan.bean.MarketIssue;
import com.cskaoyan.bean.MarketIssueExample;
import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.IssuePageInfo;
import com.cskaoyan.mapper.MarketIssueMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName:IssueServiceImpl
 * @Description:TODO
 * @author:leiwenjie
 * @date:2022/9/8 16:17
 * @version:1.0
 */
@Service
public class IssueServiceImpl implements IssueService{


    @Autowired
    MarketIssueMapper marketIssueMapper;


    @Override
    public CommonData<MarketIssue> query(IssuePageInfo info) {
        PageHelper.startPage(info.getPage(),info.getLimit());

        MarketIssueExample issueExample = new MarketIssueExample();
        issueExample.setOrderByClause(info.getSort() + " " + info.getOrder());
        if (info.getQuestion() != null&& !info.getQuestion().isEmpty()) {
            issueExample.createCriteria().andQuestionLike("%" + info.getQuestion() + "%");
        }
        List<MarketIssue> marketIssues = marketIssueMapper.selectByExample(issueExample);

        PageInfo<MarketIssue> pageInfo = new PageInfo<>(marketIssues);
        CommonData data = CommonData.data(pageInfo);
        return data;
    }

    @Override
    public void create(MarketIssue marketIssue) {
        marketIssueMapper.insert(marketIssue);
    }

    @Override
    public void update(MarketIssue issue) {
        Date date = new Date();
        issue.setUpdateTime(date);
        marketIssueMapper.updateByPrimaryKeySelective(issue);
    }

    @Override
    public void delete(MarketIssue issue) {
        marketIssueMapper.deleteByPrimaryKey(issue.getId());
    }


}
